package com.factory.iamp.pojo;

import com.alibaba.fastjson.JSONObject;
import com.factory.iamp.utils.helper.SetMethodHelper;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.sql.Timestamp;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class TableContent {
    private int cid;
    private int tid;
    private int oid;
    private String content;
    private String Scheck;
    private String Ocheck;
    private String Zcheck;
    private String problem;
    private Timestamp created_at;
    private Timestamp updated_at;

    public TableContent(JSONObject data) {
        this.SetAll(data);
    }

    public void SetAll(JSONObject data) {
        if(data.containsKey("cid")) this.cid = data.getInteger("cid");
        if(data.containsKey("tid")) this.tid = data.getInteger("tid");
        if(data.containsKey("oid")) this.oid = data.getInteger("oid");
        if(data.containsKey("content")) this.setContent(data.getJSONObject("content"));
        if(data.containsKey("Scheck")) this.Scheck = data.getString("Scheck");
        if(data.containsKey("Ocheck")) this.Ocheck = data.getString("Ocheck");
        if(data.containsKey("Zcheck")) this.Zcheck = data.getString("Zcheck");
        if(data.containsKey("problem")) this.setProblem(data.getJSONObject("problem"));
    }

    public void setContent(Object value) {
        this.content = SetMethodHelper.SetString(value);
    }

    public void setProblem(Object value) {
        this.problem = SetMethodHelper.SetString(value);
    }

    public Object ReflectGet(String name) throws Throwable {
        return TableContent.class.getDeclaredField(name).get(this);
    }
}
